<?xml version="1.0" encoding="UTF-8" ?>
<%@page import="bll.CommonBll"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@page import="util.*"%>
<%@page import="dal.*"%>
<%@ page import="model.*,java.util.*"%>
<%
	boolean embedded = MiscUtil.getBoolUrlParam(request, "embedded");
	int id = MiscUtil.getIntUrlParam(request, "id");
	QuotationModel quotation = CommonBll.loadFullQuotation(id);

	String[] trStyles = new String[] { "style=\"font-weight: bold; font-size:110%; background-color: #F7F2F2;\"",
			"style=\"font-weight: bold;\"", "", "", "", "" };
	String[] tdStyles = new String[] { "", "",
			"style=\"padding-left: 15px;\"",
			"style=\"padding-left: 30px; font-style: italic; \"", "style=\"padding-left: 45px; font-style: italic; \"" };
	
	String quotationName = quotation.getName();
	String quotationListUrl = "quotationList.jsp?idProject=" + quotation.getIdProject();

	String projectName = CacheUtil.getProjectName(quotation.getIdProject());
	String projectUrl = "project.jsp?id=" + quotation.getIdProject();
	
	List<QuotationItemModel> list = quotation.getItems();
	int size = list.size();

%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>Insert title here</title>
	<%if(!embedded){ %>
		<link rel="stylesheet" href="css/jquery-ui-1.8.14.custom.css" type="text/css" />
		<link rel="stylesheet" href="css/themes/ui-lightness/jquery.ui.all.css" />
		<link rel="stylesheet" href="css/jquery-dialog.css" />
		
		<script language="javascript" type="text/javascript" src="js/jquery-1.6.1.js"></script>
		<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
		<script language="javascript" type="text/javascript" src="js/common.js"></script>
	<%} %> 
	<link rel="stylesheet" href="css/listForm.css" />
	<link rel="stylesheet" href="css/common.css" />
	<script language="javascript" type="text/javascript">
		$(document).ready(pageLoaded);
		function pageLoaded()
		{	
			initDeleteConfirmation();
		} 
	</script>
</head>
<body>
	<%
		if (!embedded) {
	%>
	<div class="divContainer">
	<jsp:include page="menu.jsp"></jsp:include>
	<div class="divNavigation">
		<span>
			<br />			
			<b>Project: <a id="link_project" name="link_project" href="<%=projectUrl %>"><%=projectName %></a></b>&gt; 
			<b>Quotation: <%=quotationName %></b><br/><br />
			<a style="font-weight: bold;" href="quotationItemNew.jsp?idQuotation=<%=id%>">Add New Quotation Item</a><br />
			<a style="font-weight: bold;" href="<%=quotationListUrl %>">Go Up to Quotation List</a><br />
			<br />	
			<br />
		</span>
	</div>
	<% } %>	
	<div class="divListHeaderBar" style="vertical-align:  middle;">
		<span style="padding-top: 0px;">NUMBER OF QUOTATIONS: </span><%=size%>
	</div>
	<table class="tblList">
		<tr class="tblListHeader">
			<th class="thListHeader" colspan="2" rowspan="2">Quotation</th>
			<th class="thListHeader" rowspan="2">No</th>
			<th class="thListHeader" rowspan="2">Name</th>
			<th class="thListHeader" rowspan="2">Unit</th>
			<!-- <th class="thListHeader">Id Currency</th> -->
			<!-- 			<th class="thListHeader" rowspan="2">In Estimate</th> -->
			<th class="thListHeader" colspan="3">Estimate</th>
			<!-- 			<th class="thListHeader" rowspan="2">Estimate Unit Cost</th> -->
			<!-- 			<th class="thListHeader" rowspan="2">Estimate Total Amount</th> -->
			<th class="thListHeader" rowspan="2">In Quotation</th>
			<th class="thListHeader" colspan="3">Quotation</th>
			<!-- 			<th class="thListHeader">Quotation Unit Cost</th> -->
			<!-- 			<th class="thListHeader">Quotation Total Amount</th> -->
			<!-- 			<th class="thListHeader">In Internal</th> -->
			<th class="thListHeader" colspan="3">Real</th>
			<!-- 			<th class="thListHeader">Real Unit Cost</th> -->
			<!-- 			<th class="thListHeader">Real Total Amount</th> -->
			<th class="thListHeader" rowspan="2">Remark</th>
		</tr>
		<tr class="tblListHeader">
			<!-- 			<th class="thListHeader" colspan="2"></th> -->
			<!-- 			<th class="thListHeader">No</th> -->
			<!-- 			<th class="thListHeader">Name</th> -->
			<!-- 			<th class="thListHeader">Unit</th> -->
			<!-- <th class="thListHeader">Id Currency</th> -->
			<!-- 			<th class="thListHeader">In Estimate</th> -->
			<th class="thListHeader">Quantity</th>
			<th class="thListHeader">Unit Cost</th>
			<th class="thListHeader">Total Amount</th>
			<!-- 			<th class="thListHeader">In Quotation</th> -->
			<th class="thListHeader">Quantity</th>
			<th class="thListHeader">Unit Cost</th>
			<th class="thListHeader">Total Amount</th>
			<!-- 			<th class="thListHeader">In Internal</th> -->
			<th class="thListHeader">Quantity</th>
			<th class="thListHeader">Unit Cost</th>
			<th class="thListHeader">Total Amount</th>
			<!-- 			<th class="thListHeader">Remark</th> -->
			<!-- 			<th class="thListHeader"></th> -->
		</tr>
		<%
			for (int i = 0; i < size; i++) {
				QuotationItemModel obj = list.get(i);
			//for (QuotationItemModel obj : quotation.getItems()) {
		%>
		<tr class="trListItem" <%=trStyles[obj.getLevel()]%>>
			<td class="tdListInt">
				<span><%=i + 1%></span>
				<br/>
				<span class="spanEdit"><a href="quotationItem?mode=edit&id=<%=obj.getId()%>">Edit</a></span>
				<br/>
				<span class="spanEdit"><a class="hrefDelete" href="quotationItem?mode=delete&id=<%=obj.getId()%>" onclick="confirmToDelete();">Delete</a></span>
			</td>
			<td class="tdListHref" style="text-align: center;">
				<%
					if (obj.getIsGroup()) {
				%> <a
				href="quotationItem?mode=new&idQuotation=<%=obj.getIdQuotation()%>&idParent=<%=obj.getId()%> ">Add sub-item</a> 
				<% 
					} 
				%>
			</td>
			<td class="tdListText" style="text-align: center;"><%=obj.getDisplayIndexToString()%></td>
			<td class="tdListText" <%=tdStyles[obj.getLevel()]%>><%=obj.getNameToString()%></td>
			<td class="tdListInt"><%=CacheUtil.getUnitName(obj.getIdUnit())%></td>

			<%-- 			<td class="tdListBool"><%=obj.getInEstimateToString()%></td> --%>
			<td class="tdListBool"><%=obj.getEstimateQuantityToString()%></td>
			<td class="tdListNumeric"><%=obj.getEstimateUnitCostToString()%></td>
			<td class="tdListNumeric"><%=obj.getEstimateTotalAmountToString()%></td>

			<td class="tdListBool"><%=obj.getInQuotationToString()%></td>
			<td class="tdListInt"><%=obj.getQuotationQuantityToString()%></td>
			<td class="tdListNumeric"><%=obj.getQuotationUnitCostToString()%></td>
			<td class="tdListNumeric"><%=obj.getQuotationTotalAmountToString()%></td>

			<%-- 			<td class="tdListBool"><%=obj.getInInternalToString()%></td> --%>
			<td class="tdListInt"><%=obj.getInternalQuantityToString()%></td>
			<td class="tdListNumeric"><%=obj.getInternalUnitCostToString()%></td>
			<td class="tdListNumeric"><%=obj.getInternalTotalAmountToString()%></td>

			<td class="tdListTextarea"><%=obj.getRemarkToString()%></td>
		</tr>
		<%
			}
		%>
	</table>
	
	<%if(!embedded){ %> </div> <%} %>
</body>
</html>